package com.authine.cloudpivot.ext.task;

import java.util.concurrent.Delayed;
import java.util.concurrent.TimeUnit;

/**
 * @Author hxd
 * @Date 2021/11/11 11:42
 * @Description
 **/
public class TaskDelayed implements Delayed {
    private String id;
    private Runnable runnable;
    private long excuteTime;



    public Runnable getRunnable() {
        return runnable;
    }

    public long getExcuteTime() {
        return excuteTime;
    }

    public TaskDelayed(Runnable runnable,long excuteTime ) {

        this.runnable = runnable;
        this.excuteTime = excuteTime;
    }

    @Override
    public long getDelay(final TimeUnit unit) {
        return unit.convert(this.excuteTime - System.currentTimeMillis(), TimeUnit.MILLISECONDS);
    }

    @Override
    public int compareTo(final Delayed d) {
        TaskDelayed task = (TaskDelayed)d;
        return  Long.compare(excuteTime,task.getExcuteTime());

    }
}
